<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: MyBatis
  Date: 2022/10/1
  Time: 15:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>列表页面</title>
</head>
<style>
    table tr:nth-child(odd) {
        background: aquamarine;
    }

    table tr:nth-child(even) {
        background: aqua;
    }
</style>
<body>
<div>
    <table >
        <tr>
            <th>类别</th>
            <th>品种</th>
            <th>产地</th>
            <th>总重量(公斤)</th>
            <th>单价(元/公斤)</th>
            <th>操作</th>
        </tr>
        <c:forEach var="list" items="${sessionScope.list}">
            <tr>
                <td>${list.type}</td>
                <td>${list.breed}</td>
                <td>${list.area}</td>
                <td>${list.weight}</td>
                <td>${list.price}</td>
                <td><a href="SelectMapperServlet?fruitId=${list.fruitId}">详情</a>&nbsp;
                    <a href="#" onclick="remove(${list.fruitId})">删除</a> </td>
            </tr>
        </c:forEach>
    </table>
</div>
<script src="jQuery3.6.0.js"></script>
<script>
    function remove(id){
        if (confirm("确定要删除吗?")){
            $.get("DeleteMapperServlet",{fruitId:id},function (data){
                if (data>0){
                    alert("删除成功")
                }else {
                    alert("删除失败")
                }
                location.href="index.jsp"
            },"json")
        }
    }
</script>
</body>
</html>







